home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / strlib.zip / STRXNCPY.C < prev    next >
Text File  |  1993-01-04  |  2KB  |  51 lines

  1.  
  2. /*  File   : strxncpy.c
  3.     Author : Richard A. O'Keefe.
  4.     Updated: 25 may 1984
  5.     Defines: strxncpy()
  6.  
  7.     strxncpy(dst, len, src1, ..., srcn, NullS)
  8.     moves the first len characters of the concatenation of src1,...,srcn
  9.     to dst.  If there aren't that many characters, a NUL character will
  10.     be added to the end of dst to terminate it properly.  This gives the
  11.     same effect as calling strxcpy(buff, src1, ..., srcn, NullS) with a
  12.     large enough buffer, and then calling strncpy(dst, buff, len).
  13.     It is just like strncpy except that it concatenates multiple sources.
  14.     Beware: the last argument should be the null character pointer.
  15.     Take VERY great care not to omit it!  Also be careful to use NullS
  16.     and NOT to use 0, as on some machines 0 is not the same size as a
  17.     character pointer, or not the same bit pattern as NullS.
  18.  
  19.     Note: strxncpy is like strncpy in that it always moves EXACTLY len
  20.     characters; dst will be padded on the right with NUL characters as
  21.     needed.  strxnmov does the same.  strxncat, like strncat, does NOT.
  22. */
  23.  
  24. #include "strings.h"
  25. #include <varargs.h>
  26.  
  27. /*VARARGS*/
  28. char *strxncpy(va_alist)
  29.     va_dcl
  30.     {
  31.         va_list pvar;
  32.         register char *dst, *src;
  33.         register int len;
  34.         char *bogus;
  35.  
  36.         va_start(pvar);
  37.         dst = va_arg(pvar, char *);
  38.         bogus = dst;
  39.         len = va_arg(pvar, int);
  40.         src = va_arg(pvar, char *);
  41.         while (src != NullS) {
  42.             do if (--len < 0) return bogus;
  43.             while (*dst++ = *src++);
  44.             dst--;
  45.             src = va_arg(pvar, char *);
  46.         }
  47.         for (src = dst; --len >= 0; *dst++ = NUL) ;
  48.         return bogus;
  49.     }
  50.  
  51.